<script>
import {searchEnterprises} from "@/api";

export default {
  name: "srarchWindow",
  data() {
    return {
      secrchparams: {
        pageNum: 1,
        pageSize: 10,
        companyName: ''
      },
      // 企业搜索
      companyName: '',
      tableData: []
    }
  },
  created() {
  },
  methods: {
    // 搜索
    onSearch() {
      this.$forceUpdate()
      // 空值全查
      if (this.companyName === '') {
        window.alert("输入内容为空！")
        // getHot().then(res => {
        //   if (this.$route.name === "searchPage") {
        //     return res.data
        //   } else {
        //     this.$router.push({
        //       name: "searchPage",
        //       params: {
        //         data: res.data
        //       }
        //     })
        //   }
        // })
      } else {
        this.secrchparams.companyName = this.companyName
        searchEnterprises(this.secrchparams).then(res => {
          console.log(this.companyName)
          if (res.code === 2001) {
            // console.log(res.data)
            this.companyName = ''
            // 跳转页面
            if (this.$route.name === "searchPage") {
              return
            } else {
              this.$router.push({
                name: "searchPage",
                params: {
                  data: res.data.list
                }
              })
            }
          }
        })
      }

    },
  }
}
</script>

<template>
  <div style="background-color: whitesmoke">
    <div class="secrchBox">
      <!--热门搜索盒子-->
      <div class="hotSearch" style="height: 40px">
        <a-input-search v-model="companyName" placeholder="请输入查询企业"
                        enter-button="搜索企业" size="large"
                        @search="onSearch(companyName)"/>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.secrchBox {
  margin-top: 10px;
}

.hotSearch {
  height: 40px;
  line-height: 40px;
  background-color: white;
  width: 880px;
  //margin-top: 20px;
}
</style>
